# -*- coding:utf-8 -*-

# 算术运算符，主要有以下几个暂时学习
'''
+ 加
- 减
* 乘
/ 除
% 取模
** 取幂# -*- coding:utf-8 -*-
// 取整除后的整数商
'''  # -*- coding:utf-8 -*-

number = 2 ** 8  # 256
print(number)

number = 9 // 2  # 4
print(number)

# 计算1-100的和
count = 1
sum = 0
while count <= 100:
    sum = sum + count
    count = count + 1
print('1-100相加的结果为：')
print(sum)

# 计算1-2+3-4+5+...-100
count = 1
sum = 0
while count <= 100:
    if count % 2 == 0:
        sum = sum - count
    else:
        sum = sum + count
    count = count + 1
print('1-2+3-4+5+...-100运算的结果为：')
print(sum)

# 比较运算符 与java类似，跳过
'''
== 
!=
>
<
>=
<=
'''

# 赋值运算 与java类似，其中**和//java中好像没有，待确认
'''
= 简单赋值 c=a+b
+= 加法赋值运算符 c+=a 等效c=c+a
-= 减法赋值运算符 c-=a 等效c=c-a
*= 乘法赋值运算符 c*=a 等效c=c*a
/= 除法赋值运算符 c/=a 等效c=c/a
%= 取模赋值运算符 c%=a 等效c=c%a
**= 幂赋值运算符 c**=a 等效c=c**a
//= 取整除赋值运算符 c//=a 等效c=c//a
'''

# 逻辑运算符
'''
and 与
or 或
not 非
'''

# 入坑面试题
var = 1 or 9
print('运算结果为：', var)  # 1

'''
(1)字符串转数字
count=int('666')
(2)数字转字符串
score=str(666)
(3)数字转布尔
v1=bool(1)
v2=bool(9)
v3=bool(0)
(4)字符串转布尔值
v4=bool('666')
v5=bool('')
v6=bool(' ')
'''
count = int('666')
print(count) # 666

score = str(666)
print(score,type(score)) # 666 <class 'str'>

v1 = bool(1)
print(v1)  # True

v2 = bool(9)
print(v2)  # True

v3 = bool(0)
print(v3)  # False

v4 = bool('666')
print(v4)  # True

v5 = bool('')
print(v5)  # False 字符串转布尔，只有空字符串才能为false

v6 = bool(' ')
print(v6)  # True

# 转换
'''
--字符串转数字
--数字转字符串
--字符串和数字都可以转布尔型，只有字符串""和数字0，转换后都是false，其他都是true
'''

'''
官方解释：
（1）x or y 如果x是true，后面就不用看了，直接为x，如果x为false，还要看y的，结果为y 
（2）x and y 如果x为false，后面就不用看了，直接为x，如果x为true，还要看y的，结果为y
（3）not x 如果x为false，结果为True，否则为False
'''

print('---下面是or---')
var = 0 or 9
print(var)  # 9

var = 0 or ""
print('--->', var, '<---')  # --->  <---

var = 0 or 9 or 8
print(var)  # 9

print('---下面是and---')

var = 1 and 0
print(var)  # 0

var = 1 and 9
print(var)  # 9

var = 1 and ''
print('--->', var, '<---')  # --->  <---

var = 0 and 9
print(var)  # 0

var = 0 and ''
print('--->', var, '<---')  # ---> 0 <---

var = 1 and 0 and 9
print(var)  # 0

print('---下面是and和or的混合，先看and再看or---')

var = 1 and 9 or 0 and 6
print(var)  # 9

var = 5 < 4 or 3
print(var) # 3

print('---下面练习---')
# 运算符优先级 not and or 大于 比较运算符
var = 6 or 2 > 1
print(var)  # 6

var = 3 or 2 > 1
print(var)  # 3

var = 0 or 5 < 4
print(var)  # False

var = 5 < 4 or 3
print(var)  # 3

var = 2 > 1 or 6
print(var)  # True

var = 3 and 2 > 1
print(var)  # True

var = 0 and 3 > 1
print(var)  # 0

var = 2 > 1 and 3
print(var)  # 3

var = 3 > 1 and 0
print(var)  # 0

'''
下面的运算结果是2
'''
var = 3 > 1 and 2 or 2 < 3 and 3 and 4 or 3 > 2
print(var)  # 2

var = 3 > 1 and 2 or 2 < 3 and 3
print(var) # 2
